<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use think\Request;
use think\Cache;

use app\admin\model\ComValidate;
use app\admin\model\ComModel;

class Index extends Common {
	
	#站点信息#
	public function index(){
		
		if(request()->isget()){

			$this->assign('title',"站点信息");

			$this->assign('info',config('web'));
			return $this->fetch();

		}else{

			$this->log("修改站点信息");

			$data=input('post.');

			ComValidate::Site_Validate($data);
			
			
			$text="<?php
				return [
				 	
				    'name'        => '{$data['name']}', //站点名称
				    'link'=>'{$data['link']}', //站点域名
				    'logo'=>'{$data['logo']}', //站点logo
				    'keyword'=>'{$data['keyword']}' ,//关键字
				    'description'=>'{$data['description']}', //站点描述
				    'mobile'=>'{$data['mobile']}', //是否开启手机端，1启用，0 或者空关闭
				    'code'=>'{$data['code']}' ,//统计代码
				    'beian'=>'{$data['beian']}' ,//统计代码
				];";
				
			file_put_contents(ROOT_PATH ."/app/extra/web.php", $text);

			$this->success("网站信息修改成功~");
			

		}
		
	}

	#清空缓存#
	public function delcache(){

		$this->log("清除缓存");

		Cache::clear();  

		$this->success("缓存清除成功~");
	}

	#服务器信息#
	public function serverinfo(){

		$this->log("查看服务器信息");
		$this->assign('title',"服务器信息");

		$config=config("database");

		mysql_connect($config['hostname'], $config['username'], $config['password']);
		$info = array(
			'操作系统'=>PHP_OS,
			'运行环境'=>$_SERVER["SERVER_SOFTWARE"],
			'PHP服务器版本'=>PHP_VERSION,
			'Mysql版本'=>mysql_get_server_info(),
			'PHP运行方式'=>php_sapi_name(),
			'ThinkPHP版本'=>THINK_VERSION,
			'上传附件限制'=>ini_get('upload_max_filesize'),
			'执行时间限制'=>ini_get('max_execution_time').'秒',
			'服务器时间'=>date("Y年n月j日 H:i:s"),
			'北京时间'=>gmdate("Y年n月j日 H:i:s",time()+8*3600),
			'服务器域名/IP'=>$_SERVER['SERVER_NAME'].' [ '.gethostbyname($_SERVER['SERVER_NAME']).' ]',
			'剩余空间'=>function_exists(disk_free_space)?round((disk_free_space(".")/(1024*1024)),2).'M':'未知',
			'register_globals'=>get_cfg_var("register_globals")=="1" ? "ON" : "OFF",
			'magic_quotes_gpc'=>(1===get_magic_quotes_gpc())?'YES':'NO',
			'magic_quotes_runtime'=>(1===get_magic_quotes_runtime())?'YES':'NO',

		);

		$this->assign('info',$info);

		return $this->fetch();

	}

	#站点设置#
	public function siteinfo(){
		if(request()->isGet()){
			$this->assign('title',"其他设置");
			$this->assign('info',config('site'));
			return $this->fetch();
		}else{
			$data=input('post.');

			$text="<?php
				return [
				 	
				    'water'        => '{$data['water']}', //是否开启水印，text,img
				    'wate_position'=>'{$data['wate_position']}', //水印位置
				    'wate_path'=>'{$data['wate_path']}', //图片位置
				    'wate_transparent'=>'{$data['wate_transparent']}' ,//图片透明度
				    'wate_text'=>'{$data['wate_text']}', //水印文字
				    'text_font'=>'{$data['text_font']}', //水印字体
				    'text_color'=>'{$data['text_color']}' ,//字体颜色
				    'text_size'=>'{$data['text_size']}', //字体大小
				    'file_del'=>'{$data['file_del']}', //文件删除
				    'rukou'=>'{$data['rukou']}', //入口文件
				];";
				
			file_put_contents(ROOT_PATH ."/app/extra/site.php", $text);

			$this->success("网站设置修改成功~");
		}
	}

	#修改密码#
	public function modifypassword(){
		if(request()->isGet()){
			
			$this->assign("title","修改密码");
			return $this->fetch();

		}else{

			$password=input('password');
			$up=array(
				'id'=>session('admin.adminid'),
				'password'=>md5(input('password')."123456")
			);

			$r=Db::name('admin_list')->update($up);
				
			session('admin',null);
			echo $r;
			exit();

		}
	}

	


}